```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL EXPLAIN 查询优化指南 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-self;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #3b82f6 0%, #6366f1 50%, #8b5cf6 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 1;
            margin: 0 0.5rem 0 0;
            color: #3b82f6;
            font-weight: bold;
        }
        .sql-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-left: 4px solid #3b82f6;
            font-family: monospace;
        }
        .key-term {
            color: #3b82f6;
            font-weight: 500;
        }
        .tooltip {
            position: relative;
            display: inline-block;
            border-bottom: 1px dotted #64748b;
            cursor: help;
        }
        .tooltip .tooltiptext {
            visibility: hidden;
            width: 300px;
            background-color: #1e293b;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 10px;
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            margin-left: -150px;
            opacity: 0;
            transition: opacity 0.3s;
            font-size: 0.875rem;
        }
        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
        .highlight-box {
            border-left: 4px solid #10b981;
            background-color: #ecfdf5;
            padding: 1.5rem;
            margin: 1rem 0;
            border-radius: 0 0.375rem 0.375rem 0;
        }
        .nav-link {
            position: relative;
        }
        .nav-link::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -2px;
            left: 0;
            background-color: #3b82f6;
            transition: width 0.3s ease;
        }
        .nav-link:hover::after {
            width: 100%;
        }
        .scroll-indicator {
            animation: bounce 2s infinite;
        }
        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
            40% {transform: translateY(-15px);}
            60% {transform: translateY(-7px);}
        }
    </style>
</head>
<body class="antialiased">
    <!-- 导航栏 -->
    <nav class="bg-white shadow-sm sticky top-0 z-50">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16">
                <div class="flex items-center">
                    <div class="text-indigo-600 font-bold text-xl">
                        <i class="fas fa-database mr-2"></i>技术小馆
                    </div>
                </div>
                <div class="hidden md:flex items-center space-x-8">
                    <a href="#" class="text-slate-700 hover:text-indigo-600 nav-link font-medium">首页</a>
                    <a href="#" class="text-slate-700 hover:text-indigo-600 nav-link font-medium">MySQL</a>
                    <a href="#" class="text-slate-700 hover:text-indigo-600 nav-link font-medium">性能优化</a>
                    <a href="#" class="text-slate-700 hover:text-indigo-600 nav-link font-medium">教程</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Hero 模块 -->
    <div class="hero-gradient text-white">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-24">
            <div class="text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">掌握 MySQL EXPLAIN <br>提升查询性能的关键指南</h1>
                <p class="text-xl md:text-2xl font-light max-w-3xl mx-auto mb-8">深入解析 EXPLAIN 输出，精准定位 SQL 性能瓶颈</p>
                <div class="flex justify-center space-x-4">
                    <a href="#explain-intro" class="bg-white text-indigo-600 px-6 py-3 rounded-lg font-medium hover:bg-indigo-50 transition duration-300 shadow-md">
                        <i class="fas fa-play-circle mr-2"></i>开始学习
                    </a>
                    <a href="#mermaid-chart" class="bg-indigo-700 text-white px-6 py-3 rounded-lg font-medium hover:bg-indigo-800 transition duration-300 border border-indigo-300">
                        <i class="fas fa-project-diagram mr-2"></i>可视化指南
                    </a>
                </div>
            </div>
        </div>
        <div class="text-center pb-8 scroll-indicator">
            <i class="fas fa-chevron-down text-white text-2xl"></i>
        </div>
    </div>

    <!-- 主要内容 -->
    <main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- 引言部分 -->
        <section id="explain-intro" class="mb-16">
            <div class="drop-cap text-lg text-slate-700 mb-6 leading-relaxed">
                在 MySQL 的查询优化中，`EXPLAIN` 是一个非常重要的工具，它可以帮助我们理解查询是如何被执行的，从而识别潜在的性能瓶颈。通过分析 `EXPLAIN` 的输出，数据库管理员和开发人员能够做出明智的优化决策，显著提升查询性能。
            </div>
            
            <div class="highlight-box">
                <div class="flex items-start">
                    <div class="flex-shrink-0 text-emerald-500 mr-3 mt-1">
                        <i class="fas fa-lightbulb text-xl"></i>
                    </div>
                    <div>
                        <h3 class="font-bold text-lg text-slate-800 mb-2">专家提示</h3>
                        <p class="text-slate-700">在开发环境中，养成对每个复杂查询使用 `EXPLAIN` 的习惯，可以在上线前发现潜在的性能问题，避免生产环境中的性能灾难。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- 第一部分 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">1</span>
                </div>
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800">使用 EXPLAIN 命令</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="text-slate-700 mb-6 leading-relaxed">
                        <span class="key-term">EXPLAIN</span> 命令用于前置分析 SQL 查询。基本用法是将 <code class="bg-slate-100 px-1 py-0.5 rounded">EXPLAIN</code> 放在 SQL 语句的前面。
                    </p>
                    <p class="text-slate-700 mb-6 leading-relaxed">
                        这个命令会返回 MySQL 优化器如何执行查询的详细信息，包括表的读取顺序、使用的索引、估计的行数等重要信息，而不会实际执行查询。
                    </p>
                    
                    <div class="bg-indigo-50 p-4 rounded-lg border border-indigo-100 mb-6">
                        <h3 class="font-bold text-indigo-700 mb-2">基本语法</h3>
                        <div class="sql-block p-4 rounded mb-2 overflow-x-auto">
                            EXPLAIN SELECT * FROM employees WHERE department = 'Sales';
                        </div>
                        <p class="text-sm text-slate-600">在查询前添加 EXPLAIN 关键字即可获取执行计划</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-slate-800 text-white px-4 py-3">
                        <div class="flex items-center">
                            <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                            <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                            <div class="ml-auto text-sm">EXPLAIN 输出示例</div>
                        </div>
                    </div>
                    <div class="p-4">
                        <table class="min-w-full divide-y divide-slate-200">
                            <thead class="bg-slate-50">
                                <tr>
                                    <th class="px-4 py-2 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">id</th>
                                    <th class="px-4 py-2 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">select_type</th>
                                    <th class="px-4 py-2 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">table</th>
                                    <th class="px-4 py-2 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">type</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-slate-200">
                                <tr>
                                    <td class="px-4 py-2 text-sm text-slate-900">1</td>
                                    <td class="px-4 py-2 text-sm text-slate-900">SIMPLE</td>
                                    <td class="px-4 py-2 text-sm text-slate-900">employees</td>
                                    <td class="px-4 py-2 text-sm font-medium text-emerald-600">ref</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>

        <!-- 第二部分 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">2</span>
                </div>
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800">理解 EXPLAIN 输出</h2>
            </div>
            
            <p class="text-slate-700 mb-6 leading-relaxed">
                执行 <code class="bg-slate-100 px-1 py-0.5 rounded">EXPLAIN</code> 后，MySQL 会返回多个字段，每个字段都提供了查询执行计划的不同方面信息。理解这些字段对于有效优化查询至关重要。
            </p>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover mb-8">
                <div class="bg-slate-800 text-white px-4 py-3">
                    <h3 class="font-medium">EXPLAIN 输出字段详解</h3>
                </div>
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-slate-200">
                        <thead class="bg-slate-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">字段</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">描述</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">关键值</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-slate-200">
                            <tr>
                                <td class="px-6 py-4 text-sm font-medium text-slate-900">id</td>
                                <td class="px-6 py-4 text-sm text-slate-700">查询的标识符，表示查询的执行顺序</td>
                                <td class="px-6 py-4 text-sm text-slate-700">数字越小优先级越高</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 text-sm font-medium text-slate-900">select_type</td>
                                <td class="px-6 py-4 text-sm text-slate-700">查询的类型</td>
                                <td class="px-6 py-4 text-sm text-slate-700">
                                    <span class="block"><span class="font-medium">SIMPLE</span>: 简单查询</span>
                                    <span class="block"><span class="font-medium">PRIMARY</span>: 主查询</span>
                                    <span class="block"><span class="font-medium">UNION</span>: 联合查询</span>
                                </td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 text-sm font-medium text-slate-900">type</td>
                                <td class="px-6 py-4 text-sm text-slate-700">连接类型，反映查询效率</td>
                                <td class="px-6 py-4 text-sm text-slate-700">
                                    <span class="block"><span class="font-medium text-red-500">ALL</span>: 全表扫描</span>
                                    <span class="block"><span class="font-medium text-yellow-500">index</span>: 索引扫描</span>
                                    <span class="block"><span class="font-medium text-emerald-500">ref</span>: 索引查找</span>
                                    <span class="block"><span class="font-medium text-blue-500">eq_ref</span>: 等值连接</span>
                                </td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 text-sm font-medium text-slate-900">key</td>
                                <td class="px-6 py-4 text-sm text-slate-700">实际使用的索引</td>
                                <td class="px-6 py-4 text-sm text-slate-700">NULL 表示未使用索引</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 text-sm font-medium text-slate-900">rows</td>
                                <td class="px-6 py-4 text-sm text-slate-700">估算需要扫描的行数</td>
                                <td class="px-6 py-4 text-sm text-slate-700">数值越小越好</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-bold text-slate-800 mb-4">type 字段详解</h3>
                    <div class="space-y-4">
                        <div class="p-4 bg-white rounded-lg shadow-sm border border-slate-100">
                            <div class="flex items-center mb-2">
                                <div class="w-4 h-4 rounded-full bg-red-500 mr-2"></div>
                                <h4 class="font-bold text-red-500">ALL</h4>
                            </div>
                            <p class="text-slate-700 text-sm">全表扫描，性能最差。通常出现在没有使用索引或索引失效的情况下。</p>
                        </div>
                        <div class="p-4 bg-white rounded-lg shadow-sm border border-slate-100">
                            <div class="flex items-center mb-2">
                                <div class="w-4 h-4 rounded-full bg-yellow-500 mr-2"></div>
                                <h4 class="font-bold text-yellow-500">index</h4>
                            </div>
                            <p class="text-slate-700 text-sm">索引扫描，比全表扫描好，但仍需遍历索引树。</p>
                        </div>
                        <div class="p-4 bg-white rounded-lg shadow-sm border border-slate-100">
                            <div class="flex items-center mb-2">
                                <div class="w-4 h-4 rounded-full bg-emerald-500 mr-2"></div>
                                <h4 class="font-bold text-emerald-500">ref</h4>
                            </div>
                            <p class="text-slate-700 text-sm">使用索引查找，效率很好。常见于等值条件查询。</p>
                        </div>
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-slate-800 mb-4">Extra 字段关键信息</h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <div class="flex-shrink-0 text-indigo-500 mr-2 mt-1">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <div>
                                <span class="font-medium text-slate-800">Using index</span>
                                <p class="text-slate-600 text-sm">表示使用了覆盖索引，查询效率高</p>
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="flex-shrink-0 text-yellow-500 mr-2 mt-1">
                                <i class="fas fa-exclamation-triangle"></i>
                            </div>
                            <div>
                                <span class="font-medium text-slate-800">Using filesort</span>
                                <p class="text-slate-600 text-sm">需要额外的排序操作，可能影响性能</p>
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="flex-shrink-0 text-red-500 mr-2 mt-1">
                                <i class="fas fa-times-circle"></i>
                            </div>
                            <div>
                                <span class="font-medium text-slate-800">Using temporary</span>
                                <p class="text-slate-600 text-sm">需要创建临时表，性能开销大</p>
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="flex-shrink-0 text-blue-500 mr-2 mt-1">
                                <i class="fas fa-filter"></i>
                            </div>
                            <div>
                                <span class="font-medium text-slate-800">Using where</span>
                                <p class="text-slate-600 text-sm">使用了 WHERE 条件过滤</p>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- 可视化图表 -->
        <section id="mermaid-chart" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <i class="fas fa-project-diagram"></i>
                </div>
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800">EXPLAIN 优化路径可视化</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover p-6">
                <div class="mermaid">
                    graph TD
                    A[执行 EXPLAIN 查询] --> B[分析 type 字段]
                    B --> C{是否为 ALL 或 index?}
                    C -->|是| D[考虑添加索引]
                    C -->|否| E[检查可能的索引]
                    D --> F[选择合适的列创建索引]
                    E --> G[检查 key 字段]
                    G --> H{是否使用了索引?}
                    H -->|否| I[优化查询条件]
                    H -->|是| J[检查 rows 字段]
                    J --> K{rows 值是否过高?}
                    K -->|是| L[优化索引或重构查询]
                    K -->|否| M[检查 Extra 字段]
                    M --> N[解决 Using filesort/temporary]
                    N --> O[获得优化后的查询]
                </div>
            </div>
            
            <div class="mt-8 bg-blue-50 p-6 rounded-lg border border-blue-100">
                <h3 class="text-xl font-bold text-blue-800 mb-4">如何使用此流程图</h3>
                <ol class="list-decimal pl-5 space-y-3 text-blue-900">
                    <li>从顶部开始，按照箭头方向依次检查每个决策点</li>
                    <li>根据你的 EXPLAIN 输出结果选择适当的分支</li>
                    <li>按照建议采取相应的优化措施</li>
                    <li>重新运行 EXPLAIN 验证优化效果</li>
                </ol>
            </div>
        </section>

        <!-- 第三部分 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">3</span>
                </div>
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800">分析 EXPLAIN 输出</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-bold text-slate-800 mb-4">常见性能问题识别</h3>
                    <div class="space-y-6">
                        <div class="p-5 bg-white rounded-lg shadow-sm border-l-4 border-red-500">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-exclamation-triangle text-red-500 mr-2"></i>
                                <h4 class="font-bold text-slate-800">全表扫描问题</h4>
                            </div>
                            <p class="text-slate-700 text-sm">如果 <code class="bg-slate-100 px-1 py-0.5 rounded">type</code> 为 <span class="font-medium text-red-500">ALL</span>，表示查询执行了全表扫描。考虑为 WHERE 子句中的条件列添加适当的索引。</p>
                        </div>
                        
                        <div class="p-5 bg-white rounded-lg shadow-sm border-l-4 border-yellow-500">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-search-minus text-yellow-500 mr-2"></i>
                                <h4 class="font-bold text-slate-800">索引未使用</h4>
                            </div>
                            <p class="text-slate-700 text-sm">如果 <code class="bg-slate-100 px-1 py-0.5 rounded">possible_keys</code> 显示有可用索引，但 <code class="bg-slate-100 px-1 py-0.5 rounded">key</code> 为空，可能因为：</p>
                            <ul class="list-disc pl-5 mt-2 text-sm text-slate-600 space-y-1">
                                <li>查询条件不符合索引最左前缀原则</li>
                                <li>函数或计算操作导致索引失效</li>
                                <li>类型不匹配导致隐式转换</li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-bold text-slate-800 mb-4">EXPLAIN 实战分析</h3>
                    <div class="p-5 bg-slate-800 rounded-lg text-white">
                        <div class="mb-4">
                            <div class="text-sm text-slate-300 mb-1">查询示例</div>
                            <div class="sql-block p-3 rounded bg-slate-700 text-sm overflow-x-auto">
                                EXPLAIN SELECT * FROM users WHERE age > 30 AND status = 'active' ORDER BY create_time DESC;
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-2 gap-4 text-sm">
                            <div>
                                <div class="text-slate-400">type</div>
                                <div class="text-red-400 font-medium">ALL</div>
                            </div>
                            <div>
                                <div class="text-slate-400">key</div>
                                <div>NULL</div>
                            </div>
                            <div>
                                <div class="text-slate-400">rows</div>
                                <div>10,243</div>
                            </div>
                            <div>
                                <div class="text-slate-400">Extra</div>
                                <div class="text-yellow-400">Using where; Using filesort</div>
                            </div>
                        </div>
                        
                        <div class="mt-4 p-3 bg-slate-700 rounded text-sm">
                            <div class="text-emerald-400 mb-2">优化建议：</div>
                            <ul class="list-disc pl-5 space-y-1">
                                <li>为 (status, age) 创建复合索引</li>
                                <li>如果只需要部分列，考虑使用覆盖索引</li>
                                <li>添加 create_time 到索引避免 filesort</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 第四部分 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">4</span>
                </div>
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800">优化查询</h2>
            </div>
            
            <p class="text-slate-700 mb-6 leading-relaxed">
                根据 <code class="bg-slate-100 px-1 py-0.5 rounded">EXPLAIN</code> 输出的分析结果，我们可以采取多种优化手段来提升查询性能。以下是一些最有效的优化策略：
            </p>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-lg shadow-sm overflow-hidden card-hover">
                    <div class="p-5">
                        <div class="text-indigo-500 text-3xl mb-4">
                            <i class="fas fa-bolt"></i>
                        </div>
                        <h3 class="text-xl font-bold text-slate-800 mb-3">添加合适的索引</h3>
                        <p class="text-slate-600 mb-4">
                            为 WHERE 子句、JOIN 条件和 ORDER BY 子句中的列创建索引。复合索引的顺序很重要，应遵循最左前缀原则。
                        </p>
                        <div class="sql-block p-3 rounded text-sm overflow-x-auto">
                            CREATE INDEX idx_user_status ON users(status);
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-lg shadow-sm overflow-hidden card-hover">
                    <div class="p-5">
                        <div class="text-indigo-500 text-3xl mb-4">
                            <i class="fas fa-pen-fancy"></i>
                        </div>
                        <h3 class="text-xl font-bold text-slate-800 mb-3">重写查询</h3>
                        <p class="text-slate-600 mb-4">
                            简化复杂查询，避免不必要的子查询和 JOIN。考虑将复杂查询拆分为多个简单查询。
                        </p>
                        <div class="sql-block p-3 rounded text-sm overflow-x-auto">
                            -- 优化前: SELECT * FROM a WHERE id IN (SELECT a_id FROM b)
                            <br>-- 优化后: SELECT a.* FROM a JOIN b ON a.id = b.a_id
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-lg shadow-sm overflow-hidden card-hover">
                    <div class="p-5">
                        <div class="text-indigo-500 text-3xl mb-4">
                            <i class="fas fa-chess-queen"></i>
                        </div>
                        <h3 class="text-xl font-bold text-slate-800 mb-3">覆盖索引</h3>
                        <p class="text-slate-600 mb-4">
                            确保索引包含查询所需的所有列，避免回表操作。这可以显著减少 I/O 操作。
                        </p>
                        <div class="sql-block p-3 rounded text-sm overflow-x-auto">
                            -- 使用覆盖索引
                            <br>SELECT id, name FROM users WHERE status = 'active';
                            <br>CREATE INDEX idx_status_name ON users(status, name);
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 第五部分 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-indigo-100 text-indigo-600 w-10 h-10 rounded-full flex items-center justify-center mr-4">
                    <span class="font-bold">5</span>
                </div>
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800">实践示例</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="grid md:grid-cols-2 divide-y md:divide-y-0 md:divide-x divide-slate-200">
                    <div class="p-6">
                        <h3 class="text-xl font-bold text-slate-800 mb-4">优化前查询</h3>
                        <div class="sql-block p-4 rounded mb-4">
                            EXPLAIN SELECT * FROM orders WHERE customer_id = 123 AND order_date > '2023-01-01';
                        </div>
                        
                        <div class="bg-slate-50 p-4 rounded border border-slate-200">
                            <div class="grid grid-cols-2 gap-4 text-sm">
                                <div>
                                    <div class="text-slate-500">type</div>
                                    <div class="font-medium text-red-500">ALL</div>
                                </div>
                                <div>
                                    <div class="text-slate-500">rows</div>
                                    <div>8,752</div>
                                </div>
                                <div>
                                    <div class="text-slate-500">key</div>
                                    <div>NULL</div>
                                </div>
                                <div>
                                    <div class="text-slate-500">Extra</div>
                                    <div>Using where</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-4 text-sm text-slate-600">
                            <i class="fas fa-info-circle text-indigo-500 mr-1"></i> 问题分析: 全表扫描，性能较差
                        </div>
                    </div>
                    
                    <div class="p-6">
                        <h3 class="text-xl font-bold text-slate-800 mb-4">优化后查询</h3>
                        <div class="sql-block p-4 rounded mb-4">
                            CREATE INDEX idx_customer_order ON orders(customer_id, order_date);
                            <br><br>EXPLAIN SELECT * FROM orders WHERE customer_id = 123 AND order_date > '2023-01-01';
                        </div>
                        
                        <div class="bg-emerald-50 p-4 rounded border border-emerald-200">
                            <div class="grid grid-cols-2 gap-4 text-sm">
                                <div>
                                    <div class="text-slate-500">type</div>
                                    <div class="font-medium text-emerald-600">range</div>
                                </div>
                                <div>
                                    <div class="text-slate-500">rows</div>
                                    <div>42</div>
                                </div>
                                <div>
                                    <div class="text-slate-500">key</div>
                                    <div>idx_customer_order</div>
                                </div>
                                <div>
                                    <div class="text-slate-500">Extra</div>
                                    <div>Using index condition</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-4 text-sm text-slate-600">
                            <i class="fas fa-check-circle text-emerald-500 mr-1"></i> 优化效果: 扫描行数从 8,752 减少到 42，性能大幅提升
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 总结 -->
        <section class="mb-16 bg-indigo-50 rounded-xl p-8">
            <div class="text-center">
                <h2 class="text-2xl md:text-3xl font-bold text-slate-800 mb-4">MySQL EXPLAIN 优化总结</h2>
                <p class="text-slate-700 max-w-3xl mx-auto mb-6">
                    通过系统性地使用 EXPLAIN 分析查询执行计划，结合适当的优化策略，可以显著提升 MySQL 查询性能。记住，索引不是万能的，需要根据实际查询模式和数据分布来设计最优的索引策略。
                </p>
                
                <div class="grid md:grid-cols-3 gap-6 max-w-5xl mx-auto">
                    <div class="bg-white p-5 rounded-lg shadow-sm">
                        <div class="text-indigo-500 text-2xl mb-3">
                            <i class="fas fa-search"></i>
                        </div>
                        <h3 class="font-bold text-slate-800 mb-2">识别瓶颈</h3>
                        <p class="text-slate-600 text-sm">
                            通过 EXPLAIN 找出全表扫描、未使用索引等高成本操作
                        </p>
                    </div>
                    <div class="bg-white p-5 rounded-lg shadow-sm">
                        <div class="text-indigo-500 text-2xl mb-3">
                            <i class="fas fa-tools"></i>
                        </div>
                        <h3 class="font-bold text-slate-800 mb-2">优化策略</h3>
                        <p class="text-slate-600 text-sm">
                            添加索引、重写查询、使用覆盖索引等针对性优化
                        </p>
                    </div>
                    <div class="bg-white p-5 rounded-lg shadow-sm">
                        <div class="text-indigo-500 text-2xl mb-3">
                            <i class="fas fa-check-double"></i>
                        </div>
                        <h3 class="font-bold text-slate-800 mb-2">验证效果</h3>
                        <p class="text-slate-600 text-sm">
                            重新运行 EXPLAIN 确认优化效果，持续迭代改进
                        </p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer class="bg-slate-900 text-white py-12">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center">
                <div class="text-xl font-bold mb-2">技术小馆</div>
                <div class="text-slate-400 mb-6">专业的数据库技术分享平台</div>
                <a href="http://www.yuque.com/jtostring" class="text-slate-300 hover:text-white transition duration-300 inline-block">
                    <i class="fas fa-external-link-alt mr-1"></i> http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="mt-8 pt-8 border-t border-slate-800 text-center text-sm text-slate-400">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        // 初始化 Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```